<%@codepage="65001"%>
<%session.codepage="65001"%>
<!-- #include virtual=/inc/dbConn.asp -->
<!-- #include virtual=/inc/function.asp -->
<!-- #include virtual=/inc/action.header.inc.asp -->

<%
	'## 파라미터 변수 선언부
	startDt		= Request("findSartDt")
	endDt		= Request("findEndDt")
	compPrdNm		= Request("findPrdNm")

	SQLTitle = "-- ■■■■ 거래명세서 정보 그리드 List up ■■■■"
	
	'## 검색조건에 따른 조건절 만들기 
	If startDt <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " A.incomeDt >= '" & startDt & "'"
	End If 
	If endDt <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " A.incomeDt <= '" & endDt & "'"
	End If 
	If compPrdNm <> "" Then 
		If addSql <> "" Then addSql = addSql & " AND "
		addSql = addSql & " (D.etcPrdCD LIKE '%" & compPrdNm & "%' OR D.prdNm LIKE '%" & compPrdNm & "%')"
	End If 

	If addSql <> "" Then 
		addSql = " AND " & addSql 
	End If 

	SQL = "SELECT A.billCd, A.income, A.incomeDt, A.amount, A.orgAmount, A.tax, E.company, A.flag " & _
			"	FROM tblIncome A LEFT JOIN tblBizBill B ON A.billCd=B.billCd " & _
			"		LEFT JOIN tblProduct D ON B.prdCd=D.prdCd " & _ 
			"		LEFT JOIN tblCompany E ON A.compCd=E.compCd " & _ 
			"	WHERE A.billCd>0 " & addSql & _
			"  GROUP BY A.billCd, A.income, A.incomeDt, A.amount, A.orgAmount, A.tax, E.company, A.flag " & _
			"	ORDER BY A.incomeDt DESC, A.flag DESC" 

	If xMode="debug" Then 
		Call showDebug(SQLTitle,SQL) 
	End If 

	Set Rs=Server.CreateObject("ADODB.RecordSet")
	Rs.open SQL, DbCon, 1
	
	Response.write "<Incomes>" & vbcrlf

	If Rs.eof Or Rs.bof Then 
	Else 
		Do Until Rs.eof Or Rs.bof
			
			Response.write "	<BizIncome>" & vbcrlf
				Call mkXMLNode("billCd", rs("billCd"), 2)
				Call mkXMLNode("income", rs("income"), 2)
				Call mkXMLNode("company", rs("company"), 2)
				Call mkXMLNode("incomeDt", rs("incomeDt"), 2)
				Call mkXMLNode("amount", formatnumber(rs("amount"),0), 2)
				Call mkXMLNode("orgAmount", formatnumber(rs("orgAmount"),0), 2)
				Call mkXMLNode("tax", formatnumber(rs("tax"),0), 2)
				Call mkXMLNode("flag", rs("flag"), 2)
			Response.write "	</BizIncome>" & vbcrlf

		Rs.movenext
		Loop 
	End If
	Response.write "</Incomes>" & vbcrlf
'	Call rsWithXML("Save OK!")
%>